using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using CaveDigital.BoardMeeting2007Lite.ServerLib;
using System.Resources;
using CaveDigital.BoardMeeting2007Lite.Minutes;
using CaveDigital.SharedLib;

namespace CaveDigital.BoardMeeting2007Lite.Minutes
{
    public sealed class Proposal : IXmlExportable
    {
        #region ATTRIBUTES PRIVATE
        string _name;
        int _votesFavor;
        int _votesAgainst;
        int _votesAbstain;
        bool _mayorDecided;
        string _result;
        #endregion

        #region CONSTRUCTOR
        public Proposal() 
        {
            Name = string.Empty;
            Result = string.Empty;
        }

        public Proposal(string name, int votesFavor, int votesAgainst, int votesAbstain, bool mayorDecided, string result)
        {
            Name = name;
            VotesFavor = votesFavor;
            VotesAgainst = votesAgainst;
            VotesAbstain = votesAbstain;
            MayorDecided = mayorDecided;
            Result = result;
        }
        #endregion

        #region PROPERTIES PUBLIC
        public string Name
        {
            get { return _name; }
            set { _name = value == null ? string.Empty : value; }
        }
        public int VotesFavor
        {
            get { return _votesFavor; }
            set { _votesFavor = value; }
        }
        public int VotesAgainst
        {
            get { return _votesAgainst; }
            set { _votesAgainst = value; }
        }
        public int VotesAbstain
        {
            get { return _votesAbstain; }
            set { _votesAbstain = value; }
        }
        public bool MayorDecided
        {
            get { return _mayorDecided; }
            set { _mayorDecided = value; }
        }
        public string Result
        {
            get { return _result; }
            set { _result = value; }
        }
        #endregion

        #region FUNCTIONS PRIVATE
        private string processMayorDecided()
        {
            return _mayorDecided? Locals.LocalizationGetResource(MinutesConstants.RESOURCES_CAPTION_MINUTE_PROPOSAL_MAYORDECIDEDTRUE):
                Locals.LocalizationGetResource(MinutesConstants.RESOURCES_CAPTION_MINUTE_PROPOSAL_MAYORDECIDEDFALSE);
        }

        private string processResult()
        {
            return Common.IsNullOrEmpty<string>(_result) ? Locals.LocalizationGetResource(MinutesConstants.RESOURCES_CAPTION_MINUTE_PROPOSAL_NOTVOTED) :
                    _result;
        }
        #endregion

        #region IXmlExportable Members

        public void XmlExport(XmlDocument doc, XmlElement parentElement)
        {
            XmlElement topElem = doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL);
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_NAME))).InnerText = Name;
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_VOTESINFAVOR))).InnerText = VotesFavor.ToString();
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_VOTESAGAINST))).InnerText = VotesAgainst.ToString();
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_VOTESABSTAIN))).InnerText = VotesAbstain.ToString();
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_RESULT))).InnerText = processResult(); ;
            (topElem.AppendChild(doc.CreateElement(MinutesConstants.XMLNODE_PROPOSAL_MAYORDECIDED))).InnerText = processMayorDecided();
            parentElement.AppendChild(topElem);
        }
        #endregion
    }
}
